//
//  MatchmakingClient.h
//  ProjectW
//
//  Created by Nguyen Tan Loc on 7/21/12.
//  Copyright (c) 2012 __MyCompanyName__. All rights reserved.
//

#import <GameKit/GameKit.h>

typedef enum 
{
    ClientStateIdle,
    ClientStateSearchingForServer,
    ClientStateConnecting,
    ClientStateConnected,
} ClientState;

@class MatchmakingClient;
@protocol MatchmakingClientDelegate <NSObject>

-(void) matchmakingClient:(MatchmakingClient*)client serverBecameAvailable:(NSString*)peerID;
-(void) matchmakingClient:(MatchmakingClient*)client serverBecameUnavailable:(NSString*)peerID;
-(void) matchmakingClient:(MatchmakingClient *)client didDisconnectFromServer:(NSString *)peerID;
-(void) matchmakingClientNoNetwork:(MatchmakingClient*)client;

@end

@interface MatchmakingClient : NSObject <GKSessionDelegate>
{
@private 
    NSMutableArray *_availableServers;
    GKSession *_session;
    ClientState _clientState;
    id <MatchmakingClientDelegate> _delegate;
    NSString *_serverPeerID;
}

@property (nonatomic, readonly) NSArray *availableServers;
@property (nonatomic, readonly) GKSession *session;
@property (nonatomic, weak) id <MatchmakingClientDelegate> delegate;

-(void) startSearchingForServerWithSessionID:(NSString*)sessionID;
-(void) connectToServerWithPeerID:(NSString*)peerID;

-(int) getAvailableServerCount;
-(NSString*) getPeerIDForAvailableServerAtIndex:(int)index;
-(NSString*) getDisplayNameForPeerID:(NSString*)peerID;

@end
